import request from '@/utils/request'

// 注册
export const userRegisterService = ({ nickname, password, email, code }) => {
  return request.post(
    '/user/register',
    { nickname, password, email, code },
    { headers: { 'Content-Type': 'application/json' } }
  )
}

// 登录
export const userLoginService = ({ userId, password }) => {
  return request.post(
    '/user/login',
    { userId, password },
    { headers: { 'Content-Type': 'application/json' } }
  )
}

// 管理员登录
export const userLoginAdminService = ({ userId, password }) => {
  return request.post(
    '/user/login_admin',
    { userId, password },
    { headers: { 'Content-Type': 'application/json' } }
  )
}

// 邮箱验证码
export const userCodeService = (email) => {
  return request.get('/user/getCode?email=' + email)
}

// 获取个人信息
export const userGetMyService = () => {
  return request.get('/user/my_info')
}

// 修改个人信息
export const userUpdateMyService = ({
  nickname,
  avatar,
  gender,
  age,
  email,
  signature
}) => {
  return request.put(
    '/user/update',
    { nickname, avatar, gender, age, email, signature },
    {
      headers: { 'Content-Type': 'application/json' }
    }
  )
}

// 获取用户列表
export const userGetListService = (pages) => {
  return request.get('/user/list?pages=' + pages)
}

// 封禁用户
export const userDeleteService = (userId) => {
  return request.delete('/user/delete?userId=' + userId)
}
